package com.tanhua.api.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserInfoApiImpl implements UserInfoApi {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findUserInfoVo(Long userID) {
        return userInfoMapper.selectById(userID);
    }

    @Override
    public List<UserInfo> findInfoButUser(Long userId) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("id",userId);
        return userInfoMapper.selectList(queryWrapper);
    }

    @Override
    public IPage findUserAllPage(Integer page, Integer pagesize) {

        Page<UserInfo> pg = new Page<>(page,pagesize);
        IPage<UserInfo> iPage = userInfoMapper.selectPage(pg, null);//分页查询
        return iPage;
    }
}
